package com.xiaoowuu.wherecanigo

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.amap.api.services.busline.BusLineItem

/**
 * @author xiaoowuu
 */
class BusLineAdapter(val data: List<BusLineItem>) : RecyclerView.Adapter<BusLineAdapter.ViewHolder>() {
    var showBusLineDetailListener: ShowBusLineDetailListener? = null

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        return ViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.item_bus_line, parent, false))
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        holder.tvName.text = data[position].busLineName
        holder.itemView.setOnClickListener { showBusLineDetailListener?.showBusLineDetail(data[position]) }
    }

    override fun getItemCount(): Int {
        return data.size
    }

    interface ShowBusLineDetailListener {
        fun showBusLineDetail(line: BusLineItem)
    }

    class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val tvName: TextView = itemView.findViewById(R.id.tv_name)
    }
}
